// --- Copyright (c) 2006-2008 Stefan Kyntchev ---
// This software is written and copyrighted by Stefan Kyntchev 
// and BeyondPod Team members. All rights are reserved.
// Author contact: support@beyondpod.mobi
// ------------------------------------------------------------------------
// This file is part of BeyondPod RSS Feed Reader and Podcast manager
// (www.codeplex.com/BeyondPod) 
// BeyondPod is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
//  
// BeyondPod is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
// GNU General Public License for more details. 
//  
// You should have received a copy of the GNU General Public License
// along with BeyondPod. If not, see <http://www.gnu.org/licenses/>
// ------------------------------------------------------------------------
// COPYRIGHT NOTICE: This copyright notice may NOT be removed, obscured or modified 
// without written consent from the author.
// --- End copyright notice --- 


using System.Windows.Forms;
using svs.Mobile.BeyondMedia.FeedCore;
using svs.Mobile.BeyondMedia.Objects;
using svs.Mobile.BeyondMedia.Properties;
using svs.Mobile.BeyondMedia.UiCore.KineticControls;

namespace svs.Mobile.BeyondMedia.Controls
{
	/// <summary>
	/// Provide a 2 line listview
	/// </summary>
	internal class KineticOpmlView : KineticFeedsView
	{
		public KineticOpmlView() : base(false)
		{
		}

		protected override string IfEmptyText
		{
			get
			{
				return Resources.OpmlFeedIsEmpty;
			}
		}

		protected override ListViewItemData BuiltNativeControlItem(Feed feed)
		{
			var i = new ListViewItemData
			{
				Group = m_Feed.Name,
				PrimaryText = feed.Name,
				SecondaryText = feed.Feeds.Count > 0 ? feed.Feeds.Count + " Feeds" : null,
				PrimaryImage = (feed.Feeds.Count == 0 ? FeedImageList.DefaultExternalFeedImage : FeedImageList.DefaultOpmlImage),
				OverlayImage = null,
				SecondaryImage = feed.Feeds.Count > 0 ? FeedImageList.MoreArrowImage : null,
				BoldPrimary = FeedRepository.GetFeedByUrl(feed.FeedUrl) == null
			};

			if (feed.Equals(FeedRepository.GoUpPlaceholder))
			{
				i.PrimaryImage = FeedImageList.GoUpImage;
				i.PrimaryText = "Back to " + Feed.ParentFeed.Name;
			}

			return i;
		}

		protected override void FilterByCategory()
		{
			Items.AddRange(m_Feed.Feeds);
		}

		protected override void OnKeyDown(KeyEventArgs e)
		{
			switch (e.KeyCode)
			{
				case Keys.Return:

					m_IsLocalKeyUp = true;
					e.Handled = true;
					break;

				case Keys.Left:
					e.Handled = true;
					break;

				//Left Right
				case Keys.Right:
					e.Handled = true;
					break;
			}

			if (!e.Handled)
				base.OnKeyDown(e);
		}

	}
}